/**
 * 2017年11月13日
 */
package exp.algorithm.sic.feature;

import exp.algorithm.sic.TimeSeries;

/**
 * 线程安全
 * @author Alex
 *
 */

public class StatisticsFeatureMaker2 extends SegmentedKeySerieesVectorMaker{
	protected float[] getStatistics(int beginX, int length,int endX, TimeSeries ts) {
//		int segNum = 0;
//		int s = beginX;
//		while(s+length<=endX){
//			s+=length;
//			segNum ++ ;
//		}
//		System.out.printf("%d %d %d %d\n" ,beginX,length,endX,segNum);
		if(length == 0 ) 
			throw new IllegalArgumentException("TimeSeries length should > 0 begin index: "+beginX);
		float[] res = new float[3];
		float sum = 0;
		for (int i = 0; i < length; i++) {
			sum += ts.data[i + beginX];
		}
		float mean = sum / length;
		sum = 0;
		for (int i = 0; i < length; i++) {
			sum += (ts.data[i + beginX] - mean) * (ts.data[i + beginX] - mean);
		}
		float stdvar = sum / length;
		float slope = (float) Math.atan((ts.data[beginX + length - 1] / ts.data[beginX]));
		res[0] = mean;
		res[1] = stdvar;
		res[2] = slope;
		return res;
	}

}
